param(
   [string]$server = $(throw "-server is required."),
   [string]$username = $(throw "-username is required."),
   [string]$password = $(throw "-password is required."),
   [string]$command = $(throw "-command is required.")
)

<#
This script requires that the target machine allow PS Remoting, as well as CredSSP support:
Enable-PSRemoting -Force
Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1000
Enable-WSManCredSSP –Role Server # allows credssp support / prevents double-hop issue.
#>

$computerName = $server + '.rayterrill.com'
$usernameNoDomain = $username -replace "^terrill\\", ""

$securePass = convertto-securestring $password -asplaintext -force
$crd = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$securePass

#START THE SESSION
$s = New-PSSession -ComputerName $computerName -Authentication CredSSP -Credential $crd

#ACTUALLY DO WHATEVER YOU WANT TO DO
if ($command -eq 'runGet-ChildItem') {
   $output = Invoke-Command -Session $s -FilePath C:\inetpub\wwwroot\PowerShell\runGet-ChildItem.ps1
} else {
   Write-Host "Did not find a command to execute. Sorry mate."
}

#CLOSE THE SESSION
Remove-PSSession $s

Write-Host $output